package cn.lkx.servicecms.service.impl;

import cn.lkx.servicecms.entity.CrmBanner;
import cn.lkx.servicecms.mapper.CrmBannerMapper;
import cn.lkx.servicecms.service.CrmBannerService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author lkx
 * @since 2022-05-08
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {

    @Cacheable(value = "banner",key = "'getSomeBanner'") //将结果存入缓存，value:命名空间 banner::getSomeBanner
    @Override
    public List<CrmBanner> getSomeBanner() {
        //查询排名前4的 banner
        QueryWrapper<CrmBanner> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("sort");  //按sort字段 升序查询
        queryWrapper.last("limit 2"); //查4条记录
        List<CrmBanner> crmBanners = baseMapper.selectList(queryWrapper);
        return crmBanners;
    }
}
